package com.wsd.music.service.imp;

import com.wsd.music.entity.Song;
import com.wsd.music.mapper.SongMapper;
import com.wsd.music.service.SongService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SongServiceImp implements SongService {

    @Resource
    SongMapper mapper;

    /**
     * 新增歌曲
     * @param song
     * @return
     */
    @Override
    public boolean insert(Song song) {
        return mapper.insert(song) > 0;
    }

    /**
     * 修改歌曲信息
     * @param song
     * @return
     */
    @Override
    public boolean modify(Song song) {
        return mapper.modify(song) > 0;
    }

    /**
     * 通过ID删除歌曲
     * @param id
     * @return
     */
    @Override
    public boolean delete(int id) {
        return mapper.delete(id) > 0;
    }

    /**
     * 通过主键ID查询歌曲信息
     * @param id
     * @param withLyrics
     * @return
     */
    @Override
    public Song selectById(int id, boolean withLyrics) {
        if (withLyrics) return mapper.selectByIdWithLyric(id);
        return mapper.selectById(id);
    }

    /**
     * 查询所有歌曲
     * @param withLyrics
     * @return
     */
    @Override
    public List<Song> selectAll(boolean withLyrics) {
        if (withLyrics) return mapper.selectAllWithLyric();
        return mapper.selectAll();
    }

    /**
     * 通过歌曲名进行模糊查询
     * @param name
     * @param withLyrics
     * @return
     */
    @Override
    public List<Song> selectSongByName(String name, boolean withLyrics) {
        if (withLyrics) return mapper.selectSongByNameWithLyric(name);
        return mapper.selectSongByName(name);
    }

    /**
     * 根据歌名精确查询
     * @param name
     * @return
     */
    @Override
    public Song selectBySongName(String name) {
        return mapper.selectBySongName(name);
    }

    /**
     * 通过歌手查询歌曲
     * @param id
     * @param withLyrics
     * @return
     */
    @Override
    public List<Song> selectSongsBySingerId(int id, boolean withLyrics) {
        if (withLyrics) return mapper.selectSongBySingerIdWithLyric(id);
        return mapper.selectSongBySingerId(id);
    }
}
